package com.xayy.mgt.controller;


import cn.kawins.base.result.ResultBody;
import cn.kawins.mybatis.base.BaseController;
import cn.kawins.spring.mvc.validator.Group;
import com.github.pagehelper.PageInfo;
import com.xayy.mgt.model.FunctionalIndicators;
import com.xayy.mgt.model.dto.NodeInfoDto;
import com.xayy.mgt.model.vo.FunctionalIndicatorVo;
import com.xayy.mgt.service.FunctionalIndicatorsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/gnzbx1")
@Api(tags = "功能指标项")
public class FunctionalIndicatorsController extends BaseController<FunctionalIndicators> {

    @Resource
    private FunctionalIndicatorsService functionalIndicatorsService;


    @PostMapping("/saveFunctionalIndicators")
    @ApiOperation(value = "新增功能指标项")
    public ResultBody saveFunctionalIndicators(@Validated(Group.Insert.class) @RequestBody FunctionalIndicatorVo functionalIndicatorVo){
        return functionalIndicatorsService.saveFunctionalIndicators(functionalIndicatorVo).body();
    }

    @PutMapping("/updateFunctionalIndicators")
    @ApiOperation(value = "修改功能指标项")
    public ResultBody updateAssociationParameter(@RequestBody FunctionalIndicatorVo functionalIndicatorVo) {
        return functionalIndicatorsService.updateFunctionalIndicators(functionalIndicatorVo).body();
    }

    @GetMapping("/getInfo/{id}")
    @ApiOperation(value = "查看性能指标详情",response = FunctionalIndicatorVo.class)
    public ResultBody getInfo(@PathVariable Long id){
        return functionalIndicatorsService.getInfo(id).body();
    }


    @DeleteMapping("/deleteFunctionalIndicators/{id}")
    @ApiOperation(value = "删除功能指标项")
    public ResultBody deleteFunctionalIndicators(@PathVariable Long id){
        return functionalIndicatorsService.deleteFunctionalIndicators(id).body();
    }

    @PostMapping("/pageList")
    @ApiOperation(value = "功能指标（分页）")
    public ResultBody functionalPageList(@RequestBody NodeInfoDto nodeInfoDto) {
        PageInfo<FunctionalIndicators> page =  functionalIndicatorsService.pageList(nodeInfoDto);
        return ResultBody.success(page);
    }
}
